#ifndef _CCSLOT_H_
#define _CCSLOT_H_

#include "CCSpineObject.h"
#include "CCSpineGlobal.h"
#include "CCAttachment.h"
#include "cocos2d.h"

class CCSpineSprite;
class CCSkeletalSprite;

/// slot transform state
struct SlotState {
	/// color
	Color4B color;
		
	/// active skin attachment name, ccSlot doesn't copy it, so doesn't free it
	const char* activeAttachmentName;
    const char* preAttachmenName;
		
	CCSpineSprite* sprite;
        
    bool additive;
};

/**
 * slot act as a container for something, and a slot is bound with a bone.
 */
class CCSlot : public CCSpineObject {
public:
    /// flags of slot
    enum Flag {
        /// slot attachment is fixed
        FIXED_ATTACHMENT = 0x1,
        
        /// bone color is fixed
        FIXED_COLOR = 0x2
    };
	
private:
	
	/// original state
	/// activeAttachmentName of original state need to be releaseds
	SlotState m_originalState;
    
    /// flags
    int m_flags;
	
	/// state map for owner
	typedef map<CCSkeletalSprite*, SlotState> StateMap;
	StateMap m_stateMap;

protected:
	CCSlot();

public:
	virtual ~CCSlot();

	/**
	 * create a bone class
	 *
	 * @param parent parent bone, or NULL if no parent
	 */
	static CCSlot* create();

	/// get active skin attachment for an owner, or NULL if not set
	CCAttachment* getActiveAttachment(CCSkeletalSprite* owner);
	
	/// get original state
	SlotState& getOriginalState() { return m_originalState; }
	
	/// get state for an owner
	SlotState& getState(CCSkeletalSprite* owner);
	
	/// clear state of an owner
	void clearState(CCSkeletalSprite* owner);
    
    /// add a flag
    void addFlag(Flag f) { m_flags |= f; }
    
    /// remove a flag
    void removeFlag(Flag f) { m_flags &= ~f; }
    
    /// get flag
    int getFlags() { return m_flags; }
    
    /// clear flags
    void clearFlags() { m_flags = 0; }
    
    /// has flag?
    bool hasFlag(Flag f) { return (m_flags & f) != 0; }
};

#endif // __CCSlot_h__
